/*
 * Copyright (c) 2023, 2024,yzc.cn All rights reserved.
 *
 */
package com.by.server.impl;

import com.by.common.utils.AutoCode;
import com.by.common.utils.AutoData;
import com.by.mapper.PurQualityAuditMapper;
import com.by.mapper.PurQualityDetailsMapper;
import com.by.mapper.PurQualityLogsMapper;
import com.by.mapper.PurQualityMapper;
import com.by.pojo.PurQuality;
import com.by.pojo.PurQualityAudit;
import com.by.pojo.PurQualityDetails;
import com.by.pojo.PurQualityLogs;
import com.by.server.PurQualityServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>Project: erp-cloud-api - PurQualityServerImpl</p>
 * <p>Powered by yzc On 2024-01-17 16:00:22</p>
 * <p>描述：<p>
 *
 * @author yzc [yzc0415@126.com]
 * @version 1.0
 * @since 17
 */
@Service
public class PurQualityServerImpl implements PurQualityServer {
    @Autowired
    PurQualityMapper purQualityMapper;

    @Autowired
    PurQualityAuditMapper purQualityAuditMapper;

    @Autowired
    PurQualityDetailsMapper purQualityDetailsMapper;

    @Autowired
    PurQualityLogsMapper purQualityLogsMapper;

    @Transactional
    @Override
    public int save(PurQuality purQuality) {

        String code = AutoCode.autoCodePrefix("质检") + AutoData.getNowData();
        String maxCode = purQualityMapper.maxCode(code);
        String newCode = AutoCode.getNewCode(maxCode, code);
        PurQualityAudit audit =purQuality.getPurQualityAudit();
        audit.setQualityCode(newCode);
        purQualityAuditMapper.insert(audit);
        PurQualityDetails details =purQuality.getPurQualityDetails();
        details.setCode(newCode);
        purQualityDetailsMapper.insert(details);
        PurQualityLogs logs =purQuality.getPurQualityLogs();
        logs.setQualityCode(newCode);
        purQualityLogsMapper.insert(logs);





        return purQualityMapper.insert(purQuality);
    }
}
